package vip.xianz.jobmanager.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.MessageSource;

import java.util.Locale;

/**
 * 上下文工具，主要获取对象
 *
 * @author xian5
 * @create 2019 -05 -07  17:37
 */
public class ContextUtils implements ApplicationContextAware {

    private static ApplicationContext applicationContext;
    @Override
    public void setApplicationContext(ApplicationContext context) throws BeansException {
        applicationContext = context;
    }

    public static Object getBeanByClass(Class clz) {
        return applicationContext.getBean(clz);
    }

    public static String getMessage(String key, Object... args) {
        return applicationContext.getMessage(key, args, Locale.CANADA);
    }
}
